#!/usr/bin/ruby
# -*- ruby -*-
#
# http://codeforces.com/problemset/problem/399/B

require 'pp'

# While top ball is red, pop
def step1(balls, n)
  while balls[balls.size - 1] == 'R'
    balls.pop
  end

  return balls
end

# Replace top blue ball with red ball
def step2(balls, n)
  (balls.size - 1).downto(0) do |i|
    if balls[i] == 'B'
      balls[i] = 'R'

      return balls
    end
  end

  return balls
end

# Add blue balls to stack until stack has N balls
def step3(balls, n)
  while balls.size < n
    balls << 'B'
  end

  return balls
end

def done?(balls, n)
  return balls.select { |b| b== 'B' }.size <= 0
end

def play(balls, n = balls.size)
  turns = 0

  until done?(balls, n)
    balls = step1(balls, n)
    balls = step2(balls, n)
    balls = step3(balls, n)

    turns += 1
  end

  return turns
end

ARGV.each do |balls_str|
  balls = balls_str.strip.upcase.split(//).select { |c| c == 'R' || c == 'B' }

  puts play(balls)
end
